//
// Created by sgyt on 2020/1/15.
// getpwend,setpwend,endpwend 对/etc/passwd 文件进行读写

#include <stdio.h>
#include <stdlib.h>
#include <pwd.h>
#include <sys/types.h>

int main(int argc,char *agrv[])
{
    struct passwd *pass;
    int i = 0;
    for(i = 0; i<4;i++)
    {
        pass = getpwent();
        printf("pw_name:[%s],pw_passwd:[%s],pw_uid:[%d],pw_gid:[%d]\n",pass->pw_name,pass->pw_passwd,pass->pw_uid,pass->pw_gid);
    }
    //重新指向回到getpwent()
    setpwent();
    pass = getpwent();
    printf("pw_name:[%s],pw_passwd:[%s],pw_uid:[%d],pw_gid:[%d]\n",pass->pw_name,pass->pw_passwd,pass->pw_uid,pass->pw_gid);
    endpwent();
    return 0;
}

